#pragma once

#include "base_view_model.h"
#include <QString>
#include <QVector>
#include <QTimer>

namespace presentation {

/**
 * @brief 仪表板ViewModel示例
 * @details 展示如何创建新的ViewModel并集成到MVVM架构中
 */
class DashboardViewModel : public BaseViewModel {
    Q_OBJECT

    // 仪表板数据属性
    Q_PROPERTY(QString systemStatus READ systemStatus NOTIFY systemStatusChanged)
    Q_PROPERTY(int activeAgvCount READ activeAgvCount NOTIFY agvCountChanged)
    Q_PROPERTY(int pendingTaskCount READ pendingTaskCount NOTIFY taskCountChanged)
    Q_PROPERTY(QVector<QString> recentAlerts READ recentAlerts NOTIFY alertsChanged)

public:
    explicit DashboardViewModel(QObject* parent = nullptr);
    ~DashboardViewModel() override = default;

    // Override BaseViewModel methods
    void initialize() override;
    void cleanup() override;

    // Property getters
    QString systemStatus() const { return m_systemStatus; }
    int activeAgvCount() const { return m_activeAgvCount; }
    int pendingTaskCount() const { return m_pendingTaskCount; }
    QVector<QString> recentAlerts() const { return m_recentAlerts; }

    // Invokable methods for QML
    Q_INVOKABLE void refreshDashboard();
    Q_INVOKABLE void clearAlerts();
    Q_INVOKABLE void addTestAlert();

signals:
    void systemStatusChanged();
    void agvCountChanged();
    void taskCountChanged();
    void alertsChanged();

private slots:
    void onRefreshTimer();

private:
    QString m_systemStatus{"Unknown"};
    int m_activeAgvCount{0};
    int m_pendingTaskCount{0};
    QVector<QString> m_recentAlerts;
    QTimer* m_refreshTimer;

    void updateSystemStatus();
    void updateAgvCount();
    void updateTaskCount();
};

} // namespace presentation
